//
//  DDForgetPwdVC.m
//  dingdang
//
//  Created by 阮 沧晖 on 15/7/18.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDForgetPwdVC.h"
#import "DDNetWorkAPIClient.h"
@interface DDForgetPwdVC ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTF;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdTF;
@end

@implementation DDForgetPwdVC

- (void)viewDidLoad {
    NSLog(@"进入到---------->DDForgetPwdVC");
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)createUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    //自定义TAB BAR UI
//    [self addNavigatorTitle:NSLocalizedString(@"转赠积分", nil) parent:self.view];
    [self addNavigatorTitle:NSLocalizedString(@"设置支付密码", nil) parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];
    [self AddLeftBtnAction:nil normal:@"top_返回" selected:@"top_返回" action:^{
        //[self dismissViewControllerAnimated:YES completion:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

- (IBAction)submitAction:(id)sender {
    
    if (_phoneTF.text.length < 1) {
        [self delayHUD:@"请输入11位手机号码"];
        return;
    }
    if (_pwdTF.text.length < 1) {
        [self delayHUD:@"请输入新密码"];
        return;
    }
    if (_pwdTF.text.length < 6 && _pwdTF.text.length > 14) {
        [self delayHUD:@"请输入6~14位密码，建议使用数字字母组合"];
        return;
    }
    if (_confirmPwdTF.text.length < 1) {
        [self delayHUD:@"请再输入密码"];
        return;
    }
    
    if (![_pwdTF.text isEqualToString:_confirmPwdTF.text]) {
        [self delayHUD:@"两次输入密码不一致！"];
        return;
    }
    
   DDNetWorkAPIClient *network = [[DDNetWorkAPIClient alloc] init];
   [network resetPassword:_phoneTF.text phoneCode:@"12312" passwordType:@"2" password:_pwdTF.text completionBlock:^(BOOL isSuccess, NSString *message, NSString *status) {
       if (isSuccess) {
           [self delayHUD:@"修改成功"];
           [self performSelector:@selector(popVC) withObject:nil afterDelay:1.0];
       }else{
           [self delayHUD:message];
       }
}];

}


@end
